﻿
Imports System.Web.Compilation
Imports System.Web.Routing

Public Class CustomRouteHandler
	Implements IRouteHandler

	Private _virtualPath As String

	Public Sub New(ByVal vPath As String)
		_virtualPath = vPath
	End Sub

	Public Property VirtualPath() As String
		Get
			Return _virtualPath
		End Get
		Private Set(ByVal value As String)
			_virtualPath = value
		End Set
	End Property

	Public Function GetHttpHandler(requestContext As System.Web.Routing.RequestContext) As System.Web.IHttpHandler Implements System.Web.Routing.IRouteHandler.GetHttpHandler
		Dim path As String = Me.VirtualPath

		For Each value In requestContext.RouteData.Values
			path = path.Replace(String.Format("{{{0}}}", value.Key), requestContext.RouteData.Values(value.Key))
		Next

		Return BuildManager.CreateInstanceFromVirtualPath(path, GetType(Page))
	End Function

End Class
